package com.corpgovernment.common.supplier;

import com.corpgovernment.common.common.CorpBusinessException;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * 所有resultCode与对应异常的映射关系持有者
 *
 * @author xukang zhang
 * @date 2024/2/18 13:58
 */
public class ResultCodeMappingExceptionHolder {

    private final Map<Integer, CorpBusinessException> resultCodeMappingExceptionMap = new HashMap<>();

    /**
     * 注册resultCode与对应异常
     *
     * @param resultCode
     * @param exception
     */
    public void register(int resultCode, CorpBusinessException exception) {
        if (exception == null) {
            return;
        }
        resultCodeMappingExceptionMap.put(resultCode, exception);
    }

    /**
     * 获取指定resultCode的异常
     *
     * @param resultCode
     * @return
     */
    public CorpBusinessException getResponseConverter(int resultCode) {
        return resultCodeMappingExceptionMap.get(resultCode);
    }
}
